<template>
  <div class="dashboard-editor-container">
    <panel-group @handleSetLineChartData="handleSetLineChartData" />
    <el-row v-if="this.cleardashboard === '1'" :gutter="12">
      <el-col :span="16">
        <el-card shadow="hover">
          <div slot="header" class="clearfix">
            <span>项目介绍</span>
          </div>
          <div>
            <p align="center">
              <img src="https://gitee.com/UCT_admin/materials/raw/master/uctoo/UCToologo300_90.png">
            </p>
            <p align="center"><code>UCToo</code>是一款符合SaaS成熟度模型5级标准的SaaS应用开发框架，产品集成了API管理/测试、微信第三方平台、前后端快速开发组件等开发效率工具，并通过集成Cloudbase、serverless等云原生技术体系，实现了SaaS应用私有化部署、按云资源使用量付费等云原生去中心化SaaS的主要特性。可以作为SaaS产品/应用、产业互联网等数字化信息化项目的起始项目。开发成果可通过UCToo应用市场商业化分发销售。技术选型：管理后台<a href="https://www.catchadmin.com/" target="_blank">CatchAdmin</a>、移动应用<a href="https://uct-1257264070.cos-website.ap-guangzhou.myqcloud.com/" target="_blank">UCT UI</a>、云开发<a href="https://www.cloudbase.net/" target="_blank">CloudBase</a>等。</p>
            <p align="center">
              <a href="https://www.kancloud.cn/@doc_uctoo">文档</a> |
              <a href="https://demo.uctoo.com">演示地址</a> |
              <a href="https://gitee.com/uctoo/uctoo">项目源码</a> |
              <a href="https://appstore.uctoo.com">应用市场</a>
            </p>
            <p align="center">
              <el-select v-model="selectValue" placeholder="系统内置角色">
                <el-option
                        v-for="item in roles"
                        :key="item.id"
                        :label="item.role_name"
                        :value="item.id">
                </el-option>
              </el-select>
            </p>
          </div>
        </el-card>
      </el-col>
    </el-row>


    <el-row style="background:#fff;padding:16px 16px 0;margin-bottom:32px;">
      <line-chart :chart-data="lineChartData" />
    </el-row>

    <el-row :gutter="32">
      <el-col :xs="24" :sm="24" :lg="8">
        <div class="chart-wrapper">
          <raddar-chart />
        </div>
      </el-col>
      <el-col :xs="24" :sm="24" :lg="8">
        <div class="chart-wrapper">
          <pie-chart />
        </div>
      </el-col>
      <el-col :xs="24" :sm="24" :lg="8">
        <div class="chart-wrapper">
          <bar-chart />
        </div>
      </el-col>
    </el-row>

    <el-row :gutter="8">
      <el-col :xs="{span: 24}" :sm="{span: 24}" :md="{span: 24}" :lg="{span: 12}" :xl="{span: 12}" style="padding-right:8px;margin-bottom:30px;">
        <transaction-table />
      </el-col>
      <el-col :xs="{span: 24}" :sm="{span: 12}" :md="{span: 12}" :lg="{span: 6}" :xl="{span: 6}" style="margin-bottom:30px;">
        <todo-list />
      </el-col>
      <el-col :xs="{span: 24}" :sm="{span: 12}" :md="{span: 12}" :lg="{span: 6}" :xl="{span: 6}" style="margin-bottom:30px;">
        <box-card />
      </el-col>
    </el-row>
  </div>
</template>

<script>
import PanelGroup from './components/PanelGroup'
import LineChart from './components/LineChart'
import RaddarChart from './components/RaddarChart'
import PieChart from './components/PieChart'
import BarChart from './components/BarChart'
import TransactionTable from './components/TransactionTable'
import TodoList from './components/TodoList'
import BoxCard from './components/BoxCard'

const lineChartData = {
  newVisitis: {
    expectedData: [100, 120, 161, 134, 105, 160, 165],
    actualData: [120, 82, 91, 154, 162, 140, 145]
  },
  messages: {
    expectedData: [200, 192, 120, 144, 160, 130, 140],
    actualData: [180, 160, 151, 106, 145, 150, 130]
  },
  purchases: {
    expectedData: [80, 100, 121, 104, 105, 90, 100],
    actualData: [120, 90, 100, 138, 142, 130, 130]
  },
  shoppings: {
    expectedData: [130, 140, 141, 142, 145, 150, 160],
    actualData: [120, 82, 91, 154, 162, 140, 130]
  }
}

export default {
  name: 'DashboardAdmin',
  components: {
    PanelGroup,
    LineChart,
    RaddarChart,
    PieChart,
    BarChart,
    TransactionTable,
    TodoList,
    BoxCard
  },
  data() {
    return {
      lineChartData: lineChartData.newVisitis,
      cleardashboard: false,
      roles:{},
      selectValue:''
    }
  },
  computed: {
    RolesModel() {
      return this.$store.$db().model('roles');
    },
  },
  mounted() {
    this.$http.get('config?key=site.cleardashboard').then(response => {
      this.cleardashboard = response.data[0].value
      console.log(this.cleardashboard)
    });
    this.roles = this.RolesModel.all();
    console.log(this.roles);
  },
  methods: {
    handleSetLineChartData(type) {
      this.lineChartData = lineChartData[type]
    }
  }
}
</script>

<style lang="scss" scoped>
.dashboard-editor-container {
  padding: 32px;
  background-color: rgb(240, 242, 245);
  position: relative;

  .github-corner {
    position: absolute;
    top: 0px;
    border: 0;
    right: 0;
  }

  .chart-wrapper {
    background: #fff;
    padding: 16px 16px 0;
    margin-bottom: 32px;
  }
}

@media (max-width:1024px) {
  .chart-wrapper {
    padding: 8px;
  }
}
</style>
